<template>
    <div>
        <div class="order-list" v-if="orderList.length > 0">
            <div class="list-container" v-if="orderList.length > 0" v-for="(item, index) in orderList" :key="index">
                <div class="header">
                    <div class="time">{{item.create_time}}</div>
                    <div class="status">{{item.status}}</div>
                </div>
                <div class="body">
                    <div class="item-container">
                        <div class="item" v-for="(itemList, k) in item.name" :key="k">
                            <div class="left">
                                <img v-lazy="renderImg(itemList.cover)"/>
                                <span>{{itemList.name}} {{itemList.dime_name | filterDimen}}</span>
                                <span class="copies"> x {{itemList.copies}}</span>
                            </div>
                            <div class="right">￥{{itemList.copies * itemList.price}}</div>
                        </div>
                    </div>
                    <div class="item more" @click="goDetails(item.order)">查看更多</div>

                </div>
                <div class="footer">共{{item.num}}件商品，合计￥{{item.price}}</div>
            </div>
        </div>
        <div class="no-order-list" v-else>
            <div class="img-container">
                <img src="../components/common/img/emptyState.png"/>
                <div class="text">还没有订单哦</div>
            </div>
        </div>
    </div>
</template>
<script>
    import axios from '../plugins/axios';
    import _ from 'lodash'
    export default {
        async asyncData ({res, req, error}) {
            let response = {};
            let userInfo = res.locals.userInfo;
            let token = res.locals.token;
            let store_id = req.query.store;
            try {
                response = await axios.get('/api/h5/customer/order', {
                    params: {
                        customer_id: userInfo.id,
                        store_id: store_id,
                        token
                    }
                });
                response = response.data.data || [];
            } catch (e) {
                error({});
            }
            return {
                store_id,
                orderList: response,
                userInfo: userInfo,
                token: token
            }
        },
        head () {
            return {
                title: '订单列表'
            }
        },
        filters: {
            filterDimen(val){
                if (val == '/') {
                    return ''
                } else {
                    return `(${val})`
                }

            }
        },
        methods: {
            goDetails(order){
                window.location.href = `./orderDetails?store=${this.store_id}&order=${order}`
            }
        }
    }
</script>
<style lang="less" scoped>
    .order-list {
        min-height: 100vh;
        height: 100%;
        padding: 10px 20px;
        .list-container {
            background: #FFFFFF;
            box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.10);
            border-radius: 8px;
            height: 220px;
            padding: 0 20px;
            .header {
                height: 36px;
                display: flex;
                justify-content: space-between;
                line-height: 36px;
                .time {
                    font-size: 12px;
                    color: #B3B3B3;
                    letter-spacing: 0.14px;
                }
                .status {
                    font-size: 12px;
                    color: #FF5B29;
                    letter-spacing: 0.14px;
                }
            }
            .body {
                border-top: 1px solid #EDEDED;
                border-bottom: 1px solid #EDEDED;
                height: 142px;
                padding: 10px 0;
                overflow: hidden;
                .item-container {
                    height: 97px;
                    overflow: hidden;
                }
                .item {
                    display: flex;
                    justify-content: space-between;
                    height: 25px;
                    line-height: 25px;
                    .left {
                        font-size: 12px;
                        color: #000000;
                        letter-spacing: 0.14px;
                        img {
                            width: 25px;
                            height: 25px;
                            margin-right: 5px;
                            vertical-align: middle;
                            background: #eee;
                        }
                        .copies {
                            margin-left: 5px;
                        }
                    }
                    .right {
                        font-size: 12px;
                        color: #FF5B29;
                        letter-spacing: 0.14px;
                    }
                    &.more {
                        font-size: 12px;
                        color: #FF5B29;
                        letter-spacing: 0.14px;
                        align-items: center;
                        justify-content: center;
                    }
                }
                .item + .item {
                    margin-top: 10px;
                }
            }
            .footer {
                height: 36px;
                line-height: 36px;
                text-align: right;
                font-size: 12px;
                color: #000000;
                letter-spacing: 0.14px;
            }
        }
        .list-container + .list-container {
            margin-top: 10px;
        }
    }
    .no-order-list {
        flex: 1;
        height: 100vh;
        display: flex;
        justify-content: center;
        align-items: center;
        text-align: center;
        .text {
            margin-top: 30px;
            font-size: 18px;
            color: #000000;
            letter-spacing: 0.22px;
        }
    }
</style>